import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hotpot/extensions/data.dart';
import 'package:hotpot/http/http_api.dart';
import 'package:hotpot/models/create_order_req.dart';
import 'package:hotpot/models/floor.dart';
import 'package:hotpot/pages/order/widgets/confirma_pin_widget.dart';
import 'package:hotpot/pages/store/store_page.dart';
import 'package:hotpot/pages/table/table_page.dart';
import 'package:hotpot/route/route_ext.dart';
import 'package:hotpot/route/route_mixin.dart';
import 'package:hotpot/route/routes.dart';
import 'package:hotpot/utils/user_utils.dart';
import 'package:hotpot/widgets/styles/icon_box.dart';
import 'package:hotpot/widgets/widget_ext.dart';
import 'package:hotpot/widgets/z_container.dart';
import 'package:hotpot/widgets/z_image.dart';

class RequiredBannerPage extends StatefulWidget {
  const RequiredBannerPage({super.key});

  @override
  State<RequiredBannerPage> createState() => _RequiredBannerPageState();
}

class _RequiredBannerPageState extends State<RequiredBannerPage> with ArgMixin {
  late CreateOrderReq orderData;

  late FloorTables table;

  late bool required;

  late int staffId;

  var showPin = false.obs;

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        PageView(
          children: [
            ...homeImage.map((e) => ZImage.memory(bytes: e.bytes, fit: BoxFit.fill)),
          ],
        ).opacity(0.5).positioned(top: 0, bottom: 0, right: 0, left: 0),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            'Mesa '.text(size: 14, bold: true, color: Colors.white),
            table.name.text(size: 14, bold: true, color: table.color.color),
          ],
        ).positioned(top: 7, left: 0, right: 0),
        const IconBox(Icons.close, 18, 16, bgColor: Colors.transparent, color: Colors.black)
            .gestureDetector(onTap: checkPop)
            .positioned(top: 10, right: 9),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ZContainer(
              color: const Color(0xFF22CE67),
              height: 25,
              width: 94,
              radius: 18,
              alignment: Alignment.center,
              margin: const EdgeInsets.symmetric(horizontal: 17),
              child: 'Hace Pedido'.text(size: 10, bold: true, color: Colors.white),
            ).gestureDetector(onTap: () async {
              var value = await HttpApi.getSessionOrdersByTable(detail.posSession!.id!, table.id!);
              var dataList = value.result as List;
              var list = dataList.map((e) => CreateOrderReq.fromJson(e)).toList();
              CreateOrderReq orderData = list.first;
              // Routes.order.popAndPushNamed(arg: {'data': orderData, 'table': table, 'required': false});
              Routes.order
                  .popAndPushNamed(arg: {'data': orderData, 'table': table, 'required': required, 'initStaffId': staffId});
            }),
          ],
        ).positioned(left: 0, right: 0, bottom: 14),
        Column(
          children: [
            164.hSizedBox,
            // ZContainer(
            //   radius: 100,
            //   width: 95,
            //   height: 95,
            //   alignment: Alignment.center,
            //   color: const Color(0xFFD9D9D9),
            //   child: 'LOGO'.text(color: Colors.black, size: 12),
            // ),
            // ZImage.memory(bytes: UserUtils.companyImg, width: 95, height: 95, radius: 100),
            36.hSizedBox,
            'Binvenido!'.text(size: 16, bold: true, color: Colors.black),
            13.hSizedBox,
            UserUtils.companyName.text(color: Colors.black, size: 16, bold: true),
          ],
        ).alignCenter(),
        staffBox(),
      ],
    );
  }

  staffBox() {
    return Obx(
      () => ConfirmaPinWidget(
        () => showPin.value = false,
        (id) => pop(),
        shop: detail,
      ).visibility(showPin.value),
    ).positioned(right: 0, top: 0, bottom: 0, left: 0);
  }

  @override
  void loadArg(Map<String, dynamic> arg) {
    // TODO: implement loadArg
    orderData = arg['data'];
    table = arg['table'];
    required = arg['required'];
    staffId = arg['staffId'];
  }

  void checkPop() {
    showPin.value = true;
  }
}
